Logout.tsx ➔ Logout   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 16
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1.2577

Importance

Changes 0
Metric Value
cc 1
eloc 15
dl 0
loc 16
ccs 4
cts 11
cp 0.3636
crap 1.2577
rs 9.65
c 0
b 0
f 0
1
import { useDispatch } from 'react-redux';
2
import { setLoggedInOut, setCurrentUser, setToken, setRole } from '../redux/slices/authLogin';
3
import { useNavigate } from "react-router-dom";
4
import { Button, ButtonProps } from 'flowbite-react';
5
6
export default function Logout(props: ButtonProps) {
7
8 2
    const dispatch = useDispatch();
9 2
    const navigate = useNavigate();
10
11 2
    const logOutUser = (e: React.MouseEvent<HTMLButtonElement, MouseEvent>) => {
12
        e.preventDefault();
13
        dispatch(setLoggedInOut(false));
14
        dispatch(setCurrentUser(null));
15
        dispatch(setToken(''));
16
        dispatch(setRole('guest'));
17
        navigate('/');
18
    }
19 2
  return (
20
    <Button {...props} data-testid="logoutbutton" color="failure" onClick={(e) => logOutUser(e)}>Logga ut</Button>
21
  )
22
}
23